package com.cy;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Entity{
    String value() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD,ElementType.METHOD})
@interface ID{
    String value() default "";
}
@Entity("t_user")
class User{
    @ID("uid")
    private Integer id;
}

public class AnnotationTests {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> targetCls = Class.forName("com.cy.User");
        Entity entity=targetCls.getAnnotation(Entity.class);
        String entityValue=entity.value();
        System.out.println(entityValue);

        Field f = targetCls.getDeclaredField("id");
        ID id = f.getAnnotation(ID.class);
        String idValue = id.value();
        System.out.println(idValue);
    }
}
